/**
 * $Id: SimpleEntityProvider.java 77 2009-05-31 08:28:40Z azeckoski $
 * $URL: https://entitybus.googlecode.com/svn/trunk/webapp/src/main/java/org/sakaiproject/rest/providers/SimpleEntityProvider.java $
 * SimpleEntityProvider.java - EB - Feb 17, 2009 9:38:32 AM - azeckoski
 **************************************************************************
 * Copyright (c) 2008 Aaron Zeckoski
 * Licensed under the Apache License, Version 2.0
 * 
 * A copy of the Apache License has been included in this 
 * distribution and is available at: http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * Aaron Zeckoski (azeckoski @ gmail.com) (aaronz @ vt.edu) (aaron @ caret.cam.ac.uk)
 */

package org.sakaiproject.entitybus.providers;

import org.sakaiproject.entitybus.EntityReference;
import org.sakaiproject.entitybus.EntityView;
import org.sakaiproject.entitybus.entityprovider.CoreEntityProvider;
import org.sakaiproject.entitybus.entityprovider.annotations.EntityCustomAction;
import org.sakaiproject.entitybus.entityprovider.capabilities.ActionsExecutable;
import org.sakaiproject.entitybus.entityprovider.capabilities.Describeable;


/**
 * This is a simple entity provider as an example of one that is minimal
 * and just includes an action
 * 
 * @author Aaron Zeckoski (azeckoski @ gmail.com)
 */
public class SimpleEntityProvider implements CoreEntityProvider, ActionsExecutable, Describeable {

    /**
     * Sample code which will cause a return of 200 if the id is valid or 404 if not
     * @param ref the current refefrence (includes the id)
     * @return true if the ref is valid, false if not
     */
    @EntityCustomAction(action="exists", viewKey=EntityView.VIEW_SHOW)
    public boolean exists(EntityReference ref) {
        String id = ref.getId();
        return entityExists(id);
    }

    @EntityCustomAction(action="lorem", viewKey=EntityView.VIEW_LIST)
    public String loremIpsum(EntityReference ref) {
        return "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tempor quam vel orci convallis ultricies. Suspendisse potenti. Vestibulum in ante est, eu bibendum ipsum.";
    }

    /* (non-Javadoc)
     * @see org.sakaiproject.entitybus.entityprovider.CoreEntityProvider#entityExists(java.lang.String)
     */
    public boolean entityExists(String id) {
        boolean exists = false;
        if (id.equals("AZ")) {
            exists = true;
        }
        return exists;
    }

    /* (non-Javadoc)
     * @see org.sakaiproject.entitybus.entityprovider.EntityProvider#getEntityPrefix()
     */
    public String getEntityPrefix() {
        return "simple";
    }

}
